package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.OmcSetMealItemMapper;
import com.csun.cmny.provider.model.domain.OmcSetMealItem;
import com.csun.cmny.provider.model.vo.SetMealItemVo;
import com.csun.cmny.provider.service.OmcSetMealItemService;
import com.csun.cmny.provider.service.OmcSetMealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

@Service
@Slf4j
@Transactional
public class OmcSetMealItemServiceImpl extends BaseService<OmcSetMealItem> implements OmcSetMealItemService {

    @Resource
    private OmcSetMealItemMapper omcSetMealItemMapper;

    @Override
    public Integer setItemReturnStandard(List<OmcSetMealItem> omcSetMealItemList) {

        int count = 0;

        //批量设置退费标准
        for(OmcSetMealItem item : omcSetMealItemList){
            OmcSetMealItem updateItem = new OmcSetMealItem();
            updateItem.setId(item.getId());
            updateItem.setReturnStandard(item.getReturnStandard());
            int ret = omcSetMealItemMapper.updateByPrimaryKeySelective(updateItem);
            count += ret;
        }
        return count;
    }

    @Override
    public List<SetMealItemVo> queryBySetMealId(Long setMealId) {

        List<SetMealItemVo> voList = omcSetMealItemMapper.queryBySetMealId(setMealId);

//        OmcSetMealItem itemQuery = new OmcSetMealItem();
//        itemQuery.setSetmealId(setMealId);
//        List<OmcSetMealItem> setMealItemList = select(itemQuery);
//
//        if(setMealItemList.size() > 0){
//            for(OmcSetMealItem item : setMealItemList){
//                SetMealItemVo vo = new SetMealItemVo();
//                BeanUtils.copyProperties(item,vo);
//                vo.setItemName(item.getExpenseItemName());
//                vo.setContent(item.getContent());
//                voList.add(vo);
//            }
//        }
        return voList;
    }
}
